<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                template="./../template/WorkspaceTemplate.xhtml">

    <ui:define name="top">

    </ui:define>

    <ui:define name="left">

    </ui:define>

    <ui:define name="right">

    </ui:define>

    <ui:define name="content">

        <h2>Create Purchase Plan</h2>
        <h:form id="createPurchasePlanForm" style="font-size: 85%">
            <p:panel >
                <p:messages />
                <br/>
                <br/>
                <br/>
                <h:outputText value="Purchase Planning Details" style="font-weight: bold; font-size: 110%"/>
                <p:separator/>
                <br/>
                <h:panelGrid columns="2" cellpadding="10">
                    <h:outputLabel style="font-weight: bold" value="Planning Period Start Date (Monday of every week): " />
                    <p:calendar value="#{prManagerBean.date}" showOn="button" disabled="#{prManagerBean.purchasePlan != null}"/>
                    <h:outputLabel style="font-weight: bold" value="Currency: " />
                    <h:selectOneRadio value="#{prManagerBean.currency}" disabled="#{prManagerBean.purchasePlan != null}">
                        <f:selectItem itemLabel="SGD" itemValue="true"/>
                        <f:selectItem itemLabel="USD" itemValue="false"/>
                    </h:selectOneRadio>
                    <h:outputLabel style="font-weight: bold" value="Urgent: " />
                    <h:selectBooleanCheckbox value="#{prManagerBean.urgent}" disabled="#{prManagerBean.purchasePlan != null}"/>
                </h:panelGrid>
                <br/>
                <br/>
                <div align="right">
                    <p:commandButton image="ui-icon ui-icon-gear" value="Generate Planning Matrix" actionListener="#{prManagerBean.generateSupplierListRow}" update="createPurchasePlanForm purchasePlanMatrixForm" oncomplete="handleDisplayMatrix(xhr, status, args)" rendered="#{prManagerBean.purchasePlan == null}"/>
                    <p:commandButton image="ui-icon ui-icon-gear" value="Update Planning Matrix" actionListener="#{prManagerBean.updatePurchasePlan}" update="createPurchasePlanForm purchasePlanMatrixForm" oncomplete="ppmDialog.show()" rendered="#{prManagerBean.purchasePlan != null}"/>
                </div>
                <br/>
                <br/>
                <h:panelGroup id="purchasePlanForm"  style="padding: 0px" rendered="#{prManagerBean.purchasePlan != null}">
                    <h:outputText value="Purchase Orders" style="font-weight: bold; font-size: 110%"/>
                    <p:separator/>
                    <br/>
                    <p:dataTable var="po" rowIndexVar="rowIndex" value="#{prManagerBean.purchasePlan.rmpos}">

                        <p:column headerText="No." >  
                            <h:outputText value="#{rowIndex + 1}" />  
                        </p:column>

                        <p:column headerText="Supplier" >  
                            <h:outputText value="#{po.supplier.supplierName}" />  
                        </p:column>

                        <p:column headerText="Invoice No." >  
                            <h:outputText value="#{po.poNum}" />  
                        </p:column>

                        <p:column headerText="Total (SGD)" rendered="#{prManagerBean.currency}" >  
                            <h:outputText value="#{po.totalSGD}">
                                <f:convertNumber type="currency"/>
                            </h:outputText>  
                        </p:column>

                        <p:column headerText="Total (USD)" rendered="#{!prManagerBean.currency}">  
                            <h:outputText value="#{po.totalUSD}">
                                <f:convertNumber type="currency"/>
                            </h:outputText>  
                        </p:column>

                    </p:dataTable>
                    <br/>
                </h:panelGroup>
                <br/>
            </p:panel>

            <br/>
            <br/>
            <div align="right">
                <p:commandButton image="ui-icon ui-icon-disk" value="Create Purchase Plan and Purchase Orders" title="Create" action="#{prManagerBean.savePurchasePlan()}" rendered="#{prManagerBean.purchasePlan != null}"/>
            </div>
            <br/>
            <br/>
            <br/>
        </h:form>

        <script type="text/javascript">  
            function handleDisplayMatrix(xhr, status, args) {  
                if(!args.valid) {  
                    
                } else {  
                    ppmDialog.show();
                }  
            }  
        </script>


        <p:dialog header="Purchase Planning Matrix" id="ppmDialog" widgetVar="ppmDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false" closable="false" width="1280">
            <h:form id="purchasePlanMatrixForm" style="font-size: 75%">
                <p:messages />
                <br/>
                <p:dataTable var="sr" rowIndexVar="rowIndex" value="#{prManagerBean.suppliersList}" >

                    <f:facet name="header">
                        Basic Raw Materials
                    </f:facet>

                    <p:column headerText="Supplier" style="width:15%">  
                        <h:outputText value="#{sr.supplier.supplierName}" />  
                    </p:column>
                    
                    <p:column headerText="Rating" style="width:5px">  
                        <h:outputText value="#{sr.supplier.rating}">
                            <f:convertNumber pattern="#0.00"/>
                        </h:outputText>  
                    </p:column>

                    <p:column headerText="OT" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(rowIndex)}" rendered="#{sr.materialSupplied.get(0)}"/>&nbsp;&nbsp;
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm" oncomplete="ipqDialog.show()" rendered="#{sr.materialSupplied.get(0)}">
                            <f:attribute name="index" value="#{0}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:column headerText="WG" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(1)}" rendered="#{sr.materialSupplied.get(1)}"/>&nbsp;&nbsp;
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm" oncomplete="ipqDialog.show()" rendered="#{sr.materialSupplied.get(1)}">
                            <f:attribute name="index" value="#{1}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:column headerText="CM" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(2)}" rendered="#{sr.materialSupplied.get(2)}"/>&nbsp;&nbsp;
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm" oncomplete="ipqDialog.show()" rendered="#{sr.materialSupplied.get(2)}">
                            <f:attribute name="index" value="#{2}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:column headerText="NM" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(3)}" rendered="#{sr.materialSupplied.get(3)}"/>&nbsp;&nbsp;
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm" oncomplete="ipqDialog.show()" rendered="#{sr.materialSupplied.get(3)}">
                            <f:attribute name="index" value="#{3}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:column headerText="CL" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(4)}" rendered="#{sr.materialSupplied.get(4)}"/>&nbsp;&nbsp;  
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm" oncomplete="ipqDialog.show()" rendered="#{sr.materialSupplied.get(4)}">
                            <f:attribute name="index" value="#{4}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:column headerText="HO" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(5)}" rendered="#{sr.materialSupplied.get(5)}"/>&nbsp;&nbsp;
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm" oncomplete="ipqDialog.show()" rendered="#{sr.materialSupplied.get(5)}">
                            <f:attribute name="index" value="#{5}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:column headerText="CO" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(6)}" rendered="#{sr.materialSupplied.get(6)}"/>&nbsp;&nbsp;  
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm" oncomplete="ipqDialog.show()" rendered="#{sr.materialSupplied.get(6)}">
                            <f:attribute name="index" value="#{6}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:columnGroup type="footer">  
                        <p:row>  
                            <p:column colspan="2" footerText="Total Requirements:"  
                                      style="text-align:right"  />  
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(0)}" />
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(1)}" />
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(2)}" />
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(3)}" />
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(4)}" />
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(5)}" />
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(6)}" />
                        </p:row>  
                    </p:columnGroup> 


                </p:dataTable>

                <br/>
                <br/>

                <p:dataTable var="sr" rowIndexVar="rowIndex" value="#{prManagerBean.suppliersList}">

                    <f:facet name="header">
                        Powder Raw Materials
                    </f:facet>

                    <p:column headerText="Supplier" style="width:15%">  
                        <h:outputText value="#{sr.supplier.supplierName}" />  
                    </p:column>
                    
                    <p:column headerText="Rating" style="width:5px">  
                        <h:outputText value="#{sr.supplier.rating}">
                            <f:convertNumber pattern="#0.00"/>
                        </h:outputText>  
                    </p:column>

                    <p:column headerText="VM" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(7)}" rendered="#{sr.materialSupplied.get(7)}"/>&nbsp;&nbsp;
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm"  rendered="#{sr.materialSupplied.get(7)}" oncomplete="ipqDialog.show()">
                            <f:attribute name="index" value="#{7}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:column headerText="CC" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(8)}" rendered="#{sr.materialSupplied.get(8)}"/>&nbsp;&nbsp;
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm" rendered="#{sr.materialSupplied.get(8)}" oncomplete="ipqDialog.show()">
                            <f:attribute name="index" value="#{8}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:column headerText="PP" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(9)}" rendered="#{sr.materialSupplied.get(9)}"/>&nbsp;&nbsp;  
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm"  rendered="#{sr.materialSupplied.get(9)}" oncomplete="ipqDialog.show()">
                            <f:attribute name="index" value="#{9}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:column headerText="CP" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(10)}" rendered="#{sr.materialSupplied.get(10)}"/>&nbsp;&nbsp;  
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm"  rendered="#{sr.materialSupplied.get(10)}" oncomplete="ipqDialog.show()">
                            <f:attribute name="index" value="#{10}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:column headerText="HM" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(11)}" rendered="#{sr.materialSupplied.get(11)}"/>&nbsp;&nbsp;  
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm"  rendered="#{sr.materialSupplied.get(11)}" oncomplete="ipqDialog.show()">
                            <f:attribute name="index" value="#{11}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:columnGroup type="footer">  
                        <p:row>  
                            <p:column colspan="2" footerText="Total Requirements:"  
                                      style="text-align:right"  />  
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(7)}" />
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(8)}" />
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(9)}" />
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(10)}" />
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(11)}" />
                        </p:row>  
                    </p:columnGroup> 

                </p:dataTable>
                <br/>
                <br/>

                <p:dataTable  var="sr" rowIndexVar="rowIndex" value="#{prManagerBean.suppliersList}" >

                    <f:facet name="header">
                        Fruits and Nuts Raw Materials
                    </f:facet>

                    <p:column headerText="Supplier" style="width:15%">  
                        <h:outputText value="#{sr.supplier.supplierName}" />  
                    </p:column>
                    
                    <p:column headerText="Rating" style="width:5px">  
                        <h:outputText value="#{sr.supplier.rating}">
                            <f:convertNumber pattern="#0.00"/>
                        </h:outputText>  
                    </p:column>

                    <p:column headerText="CN" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(12)}" rendered="#{sr.materialSupplied.get(12)}"/>&nbsp;&nbsp;  
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm"  rendered="#{sr.materialSupplied.get(12)}" oncomplete="ipqDialog.show()">
                            <f:attribute name="index" value="#{12}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:column headerText="WN" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(13)}" rendered="#{sr.materialSupplied.get(13)}"/>&nbsp;&nbsp;  
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm"  rendered="#{sr.materialSupplied.get(13)}" oncomplete="ipqDialog.show()">
                            <f:attribute name="index" value="#{13}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:column headerText="AL" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(14)}"  rendered="#{sr.materialSupplied.get(14)}"/>&nbsp;&nbsp;
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm"  rendered="#{sr.materialSupplied.get(14)}" oncomplete="ipqDialog.show()">
                            <f:attribute name="index" value="#{14}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:column headerText="MD" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(15)}"  rendered="#{sr.materialSupplied.get(15)}"/>&nbsp;&nbsp;
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm"  rendered="#{sr.materialSupplied.get(15)}" oncomplete="ipqDialog.show()">
                            <f:attribute name="index" value="#{15}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:column headerText="RC" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(16)}"  rendered="#{sr.materialSupplied.get(16)}"/>&nbsp;&nbsp;
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm"  rendered="#{sr.materialSupplied.get(16)}" oncomplete="ipqDialog.show()">
                            <f:attribute name="index" value="#{16}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:column headerText="RS" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(17)}"  rendered="#{sr.materialSupplied.get(17)}"/>&nbsp;&nbsp;
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm"  rendered="#{sr.materialSupplied.get(17)}" oncomplete="ipqDialog.show()">
                            <f:attribute name="index" value="#{17}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:column headerText="DT" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(18)}"  rendered="#{sr.materialSupplied.get(18)}"/>&nbsp;&nbsp;
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm"  rendered="#{sr.materialSupplied.get(18)}" oncomplete="ipqDialog.show()">
                            <f:attribute name="index" value="#{18}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:column headerText="AR" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(19)}" rendered="#{sr.materialSupplied.get(19)}"/>&nbsp;&nbsp;  
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm"  rendered="#{sr.materialSupplied.get(19)}" oncomplete="ipqDialog.show()">
                            <f:attribute name="index" value="#{19}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:column headerText="KW" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(20)}" rendered="#{sr.materialSupplied.get(20)}"/>&nbsp;&nbsp;  
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm"  rendered="#{sr.materialSupplied.get(20)}" oncomplete="ipqDialog.show()">
                            <f:attribute name="index" value="#{20}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:column headerText="AP" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(21)}"  rendered="#{sr.materialSupplied.get(21)}"/>&nbsp;&nbsp;
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm"  rendered="#{sr.materialSupplied.get(21)}" oncomplete="ipqDialog.show()">
                            <f:attribute name="index" value="#{21}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:column headerText="PE" style="width: 2px">
                        <h:outputText style="width: 50px"  value="#{sr.purchases.get(22)}"  rendered="#{sr.materialSupplied.get(22)}"/>&nbsp;&nbsp;
                        <p:commandButton image="ui-icon ui-icon-pencil" actionListener="#{prManagerBean.editQuantity}" update="purchasePlanMatrixForm inputPurchaseQuantityForm"  rendered="#{sr.materialSupplied.get(22)}" oncomplete="ipqDialog.show()">
                            <f:attribute name="index" value="#{22}"/>
                            <f:attribute name="supplierRow" value="#{sr}"/>
                        </p:commandButton>
                    </p:column>

                    <p:columnGroup type="footer">  
                        <p:row>  
                            <p:column colspan="2" footerText="Total Requirements:"  
                                      style="text-align:right"  />  
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(12)}" />
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(13)}" />
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(14)}" />
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(15)}" />
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(16)}" />
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(17)}" />
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(18)}" />
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(19)}" />
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(20)}" />
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(21)}" />
                            <p:column colspan="1" footerText="#{prManagerBean.requirements.get(22)}" />
                        </p:row>  
                    </p:columnGroup> 

                </p:dataTable>

                <br/>
                <br/>
                <br/>

                <h:panelGrid columns="1" style="font-size: 85%; border-style: solid; border-width: thin; width: 100%; padding: 10px" >

                    <h:outputText value="Legend" style="font-weight: bold; font-size: 110%"/>
                    <p:separator/>
                    <h:panelGrid columns="5" cellpadding="0 20" style="width: 100%">
                        <h:outputText value="OT - Oats" />
                        <h:outputText value="WG - Wheat Germ" />
                        <h:outputText value="CM - Cinnamon" />
                        <h:outputText value="NM - Nutmeg" />
                        <h:outputText value="CL - Cloves" />
                        <h:outputText value="HO - Honey" />
                        <h:outputText value="CO - Canola Oil" />
                        <h:outputText value="VM - Vitamin / Mineral Powder" />
                        <h:outputText value="CC - Carob Chips" />
                        <h:outputText value="PP - Protein Powder" />
                        <h:outputText value="CP - Cocoa Powder" />
                        <h:outputText value="HN - Hazenuts" />
                        <h:outputText value="CN - Cashew Nuts" />
                        <h:outputText value="WN - Walnuts" />
                        <h:outputText value="AL - Almonds" />
                        <h:outputText value="MD - Macadamias" />
                        <h:outputText value="RC - Redcurrants" />
                        <h:outputText value="RS - Rasins" />
                        <h:outputText value="DT - Dates" />
                        <h:outputText value="AR - Apricots" />
                        <h:outputText value="KW - Kiwis" />
                        <h:outputText value="AP - Apples" />
                        <h:outputText value="PE - Peaches" />
                    </h:panelGrid>
                </h:panelGrid>

                <br/>
                <br/>
                <div align="right">
                    <p:commandButton image="ui-icon ui-icon-close" value="Cancel" update="purchasePlanMatrixForm createPurchasePlanForm" oncomplete="ppmDialog.hide()" rendered="#{prManagerBean.purchasePlan == null}"/>
                    <p:commandButton image="ui-icon ui-icon-close" value="Cancel" actionListener="#{prManagerBean.cancelUpdatePurchasePlan}" update="purchasePlanMatrixForm createPurchasePlanForm" oncomplete="ppmDialog.hide()" rendered="#{prManagerBean.purchasePlan != null}"/> 
                    <p:commandButton image="ui-icon ui-icon-disk" value="Generate Purchase Plan" actionListener="#{prManagerBean.generatePurchasePlan}" update="purchasePlanMatrixForm createPurchasePlanForm" oncomplete="handleCreatePurchasePlan(xhr, status, args)" />
                </div>
                <br/>
                <br/>

            </h:form>
        </p:dialog>

        <script type="text/javascript">  
            function handleCreatePurchasePlan(xhr, status, args) {  
                if(!args.valid) {  
                    jQuery('#ppmDialog').parent().effect("shake", { times:3 }, 100);
                } else {  
                    ppmDialog.hide();
                }  
            }  
        </script>

        <p:dialog header="Input Purchase Quantity" id="ipqDialog" widgetVar="ipqDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false" closable="false" width="600">
            <h:form id="inputPurchaseQuantityForm">
                <h:panelGrid columns="2" cellpadding="10">
                    <h:outputLabel style="font-weight: bold" value="Raw Material: "/>
                    <h:outputText value="#{prManagerBean.sr.materials.get(prManagerBean.index).name}"/>
                    <h:outputLabel style="font-weight: bold" value="Price (SGD): " rendered="#{prManagerBean.currency}"/>
                    <h:outputText value="#{prManagerBean.rmsi.unitPriceSGD}" rendered="#{prManagerBean.currency}">
                        <f:convertNumber type="currency"/>
                    </h:outputText>
                    <h:outputLabel style="font-weight: bold" value="Price (USD): " rendered="#{!prManagerBean.currency}"/>
                    <h:outputText value="#{prManagerBean.rmsi.unitPriceUSD}" rendered="#{!prManagerBean.currency}">
                        <f:convertNumber type="currency"/>
                    </h:outputText>
                    <h:outputLabel style="font-weight: bold" value="Supplier: "/>
                    <h:outputText value="#{prManagerBean.sr.supplier.supplierName}"/>
                    <h:outputLabel style="font-weight: bold" value="Quantity: "/>
                    <h:inputText value="#{prManagerBean.quantity}"/>
                </h:panelGrid>
                <br/>
                <br/>
                <div align="right">
                    <p:commandButton image="ui-icon ui-icon-close" value="Close" actionListener="#{prManagerBean.cancelEditQuantity}" update="purchasePlanMatrixForm" oncomplete="ipqDialog.hide()"/>
                    <p:commandButton image="ui-icon ui-icon-check" value="Confirm" actionListener="#{prManagerBean.updateEditQuantity}" update="purchasePlanMatrixForm" oncomplete="ipqDialog.hide()"/>
                </div>
                <br/>
                <br/>
            </h:form>
        </p:dialog>



    </ui:define>

    <ui:define name="bottom">

    </ui:define>

</ui:composition>
